package com.animation_study.eventbus

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import com.animation_study.R
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

class ReceiveMsgActivity : AppCompatActivity() {

    var tv_receive_msg: TextView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_receive_msg)

        tv_receive_msg = findViewById(R.id.tv_receive_msg) as? TextView
        EventBus.getDefault().register(this)
    }

    @Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    fun messageEventBussticky(event: StickyEvent) {
        tv_receive_msg!!.setText(event.msg)
    }

    override fun onDestroy() {

        EventBus.getDefault().unregister(ReceiveMsgActivity::class.java)
        super.onDestroy()
    }

}
